Page({
  goDetail(ev) {
    wx.navigateTo({
      url: '/repair_pkg/pages/detail/index?id='+ev.mark.id,
    })
  },
  addRepair() {
    wx.navigateTo({
      url: '/repair_pkg/pages/form/index',
    })
  },
  data: {
    repairList: [],
    isEmpty: false,
    total: 0,
    params: {
      current: 1,
      pageSize: 4,
    },
    refreshing: false,
  },
  onLoad() {
    this.getRepairList()
  },
  async getRepairList() {
    const {
      code,
      data: { rows: repairList, total },
    } = await wx.http.get('/repair', this.data.params)
    if (code !== 10000) return wx.utils.toast()
    this.setData({
      repairList: [...this.data.repairList, ...repairList],
      isEmpty: repairList.length === 0,
      total: total,
    })
    if (this.data.repairList.length < total) {
      this.setData({
        params: {
          current: this.data.params.current + 1,
          pageSize: this.data.params.pageSize,
        },
      })
    }
  },
  getNextPage() {
    if (this.data.repairList.length < this.data.total) {
      this.getRepairList()
    }
  },
  refreshPage() {
    this.setData({
      repairList: [],
      isEmpty: false,
      total: 0,
      params: {
        current: 1,
        pageSize: 4,
      },
    })
    this.getRepairList()
    this.setData({
      refreshing:false
    })
  },
})
